package boss.portal.util;

import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ToolUtil {

    //验证手机号码
    public static boolean isMobile(String phone){
        boolean flag = false;
        try {
            if (StringUtils.isEmpty(phone)){
                return flag;
            }
            Pattern p = Pattern.compile("^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$");
            Matcher m = p.matcher(phone);
            flag = m.matches();
        }catch (Exception e){
            flag = false;
        }
        return flag;
    }


    //验证邮箱
    public static boolean isEmail(String email){
        boolean flag = false;
        try {
            if (StringUtils.isEmpty(email)){
                return flag;
            }
            Pattern p = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
            Matcher m = p.matcher(email);
            flag = m.matches();
        }catch (Exception e){
            flag = false;
        }
        return flag;
    }

    public static void main(String[] args) {
        System.out.println(isMobile("15763824909"));
    }
}
